home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WOLESOBJ.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  10.4 KB  |  300 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WOleServerObject -- Ole Server Object class
  14.  *
  15.  *
  16.  *   Events:
  17.  *
  18.  *      QueryInterface          -- QueryInterface event
  19.  *
  20.  *************************************************************************/
  21.  
  22. #ifndef _WOLESOBJ_HPP_INCLUDED
  23. #define _WOLESOBJ_HPP_INCLUDED
  24.  
  25. #ifndef _WNO_PRAGMA_PUSH
  26. #pragma pack(push,8);
  27. #pragma enum int;
  28. #endif
  29.  
  30. #ifndef _WOLETYPE_HPP_INCLUDED
  31. #   include "woletype.hpp"
  32. #endif
  33. #ifndef _WOLEAUTO_HPP_INCLUDED
  34. #   include "woleauto.hpp"
  35. #endif
  36. #ifndef _WSTRING_HPP_INCLUDED
  37. #   include "wstring.hpp"
  38. #endif
  39. #ifndef _WRECT_HPP_INCLUDED
  40. #   include "wrect.hpp"
  41. #endif
  42. #ifndef _WPALETTE_HPP_INCLUDED
  43. #   include "wpalette.hpp"
  44. #endif
  45.  
  46. #define OPTIMA_COMPONENT_KEY_STR        "OptimaOleComponent"
  47.  
  48. // forward class declarations
  49. class WCMCLASS WApplication;
  50. class WCMCLASS WOleClassManager;
  51. class WCMCLASS WOleServerObject;
  52. class WCMCLASS WOleServerObjectListEntry;
  53. class WCMCLASS WOleServerObjectRegistryData;
  54. class WCMCLASS WOleServerObject_IUnk;
  55. class WCMCLASS wllist_header;
  56. class WCMCLASS WOleInterfaceFamily;
  57. class IOleClientSite;
  58.  
  59. typedef WOleServerObject * WCMDEF (*pfnOleSvrCreateInst)( WPIUnknown pUnkOuter );
  60. typedef WBool WCMDEF (*pfnOleSvrIsEqualClassID)( const WCLSID & clsid );
  61.  
  62. struct WOleServerObjectRegistryDataBlock {
  63.     WChar *_progID;
  64.     WChar *_viProgID;
  65.     WChar *_appFullName;
  66.     WChar *_appShortName;
  67.     WBool _insertable;
  68.     WBool _isOleControl;
  69.     WInt  _versionMajor;
  70.     WInt  _versionMinor;
  71. };
  72.  
  73. class WCMCLASS WOleServerObjectRegistryData {
  74.     public:
  75.         WOleServerObjectRegistryData( const WCLSID & clsid, WOleServerObjectRegistryDataBlock * );
  76.         ~WOleServerObjectRegistryData( void );
  77.  
  78.         // Self Registration
  79.         WBool Register( WApplication *application );
  80.         WBool Unregister( WApplication *application );
  81.  
  82.         WCLSID                                  _classID;
  83.         WOleServerObjectRegistryDataBlock       *_registryDataBlock;
  84.  
  85.         static WOleServerObjectRegistryData     *Head;
  86.         WOleServerObjectRegistryData            *next;
  87. };
  88.  
  89. // QueryInterface event data structure
  90. struct WQueryInterfaceEventData : public WEventData {
  91.     WCLSID      wclsid;
  92.     WPIUnknown  pIUnknown;
  93. };
  94.  
  95. // the following is definitions of WOleServerObject
  96.  
  97. class WCMCLASS WOleServerObject : public WEventGenerator {
  98.     WDeclareSubclass( WOleServerObject, WEventGenerator );
  99.  
  100.     friend class WOleServerObject_IUnk;
  101.  
  102.     public:
  103.  
  104.         /**********************************************************
  105.          * Constructors and Destructors
  106.          *********************************************************/
  107.  
  108.         WOleServerObject();
  109.         virtual ~WOleServerObject();
  110.  
  111.         WBool Create( WOleClassManager * );
  112.         WBool Destroy( void );
  113.  
  114.     public:
  115.  
  116.         /**************************************************************
  117.          * Properties
  118.          **************************************************************/
  119.  
  120.         // Prog ID
  121.         WString GetProgID( void ) const;
  122.  
  123.         // Version Independent Prog ID
  124.         WString GetVersionIndependentProgID( void ) const;
  125.  
  126.         // Version Major
  127.         WInt GetVersionMajor( void ) const;
  128.  
  129.         // Version Minor
  130.         WInt GetVersionMinor( void ) const;
  131.  
  132.         // Application Full Name
  133.         WString GetApplicationFullName( void ) const;
  134.  
  135.         // Application Short Name ( 15 chars max )
  136.         WString GetApplicationShortName( void ) const;
  137.  
  138.         // IsInsertable
  139.         WBool GetIsInsertable( void ) const;
  140.  
  141.         // IsOleControl
  142.         WBool GetIsOleControl( void ) const;
  143.  
  144.         // IUknown interface
  145.         WPIUnknown GetIUnknown( WBool addRef=TRUE ) const;
  146.  
  147.         // Number of InterfaceFamilies
  148.         WInt GetNumInterfaceFamilies( void ) const;
  149.  
  150.         // Client Site pointer
  151.         IOleClientSite *GetClientSite( void );
  152.         void SetClientSite( IOleClientSite * );
  153.  
  154.         // Ambient Properties
  155.         WBool GetAmbientProperty( WDispID, WVariant * );
  156.  
  157.         // Extents
  158.         WBool SetExtent( WDWord, WRect );
  159.         WRect *GetExtent( WDWord );
  160.  
  161.         // Acts Like Button Property
  162.         void SetActsLikeButton( WBool set = TRUE );
  163.         WBool GetActsLikeButton( void );
  164.  
  165.         // Acts Like label Property
  166.         void SetActsLikeLabel( WBool set = TRUE );
  167.         WBool GetActsLikeLabel( void );
  168.  
  169.         // Alignable property
  170.         void SetAlignable( WBool set = TRUE );
  171.         WBool GetAlignable( void );
  172.  
  173.         // Container Name
  174.         WBool SetContainerName( WString );
  175.         WString GetContainerName( void );
  176.  
  177.         // Application Name
  178.         WBool SetApplicationName( WString );
  179.         WString GetApplicationName( void );
  180.  
  181.         // Colour Scheme
  182.         WBool SetColorScheme( WColorArray );
  183.         WColorArray GetColorScheme( void );
  184.  
  185.         /**************************************************************
  186.          * Static Methods
  187.          **************************************************************/
  188.  
  189.         // Self Registration
  190.         static WBool Register( WApplication *application );
  191.         static WBool Unregister( WApplication *application );
  192.  
  193.         /**************************************************************
  194.          * Methods
  195.          **************************************************************/
  196.  
  197.         // Add an Interface Family
  198.         WBool AddInterfaceFamily( WOleInterfaceFamily *interfaceFamily );
  199.  
  200.         // Specify RegistryData
  201.         WBool SetRegistryData( WOleServerObjectRegistryData * );
  202.         WOleServerObjectRegistryData *GetRegistryData( void ) const;
  203.  
  204.         // Reference counting
  205.         WULong AddRef( void );
  206.         WULong Release( void );
  207.  
  208.         // Get the servers WCLSID
  209.         virtual WCLSID OleClassID( void );
  210.  
  211.         /**************************************************************
  212.          * Item Properties
  213.          **************************************************************/
  214.  
  215.         WOleInterfaceFamily *GetInterfaceFamily( WInt index ) const;
  216.         WOleInterfaceFamily *GetInterfaceFamily( const WString & className ) const;
  217.  
  218.         /**************************************************************
  219.          * Internal Methods
  220.          **************************************************************/
  221.  
  222.         // Aggregating IUnknown
  223.         WBool SetUnkOuter( WPIUnknown pUnkOuter );
  224.         WPIUnknown GetUnkOuter( void ) const;
  225.  
  226.     protected:
  227.  
  228.         WBool QueryInterfaceFamilies( const WCLSID & clsid, void **iface );
  229.  
  230.     /**********************************************************
  231.      * Data Members
  232.      *********************************************************/
  233.     
  234.     protected:
  235.         WULong                          _refCount;
  236.         WPIUnknown                      _pUnkOuter;
  237.         WOleServerObject_IUnk           *_iunknown;
  238.         wllist_header                   *_ifamilyList;
  239.         WOleClassManager                *_classManager;
  240.         WOleServerObjectRegistryData    *_registryData;
  241.         IOleClientSite                  *_pClientSite;
  242.         WRect                           *_pContentExtent;
  243.         WRect                           *_pIconicExtent;
  244.         WBool                           _actsLikeLabel;
  245.         WBool                           _actsLikeButton;
  246.         WBool                           _alignable;
  247.         WString                         _containerName;
  248.         WString                         _appName;
  249.         WColorArray                     _palette;
  250.  
  251. };
  252.  
  253. class WCMCLASS WOleServerObjectListEntry {
  254.     public:
  255.         WOleServerObjectListEntry( pfnOleSvrCreateInst pfn, const WCLSID & clsid );
  256.         ~WOleServerObjectListEntry( void );
  257.  
  258.         pfnOleSvrCreateInst                     fnCreateInst;
  259.         WCLSID                                  classID;
  260.         static WOleServerObjectListEntry        *Head;
  261.         WOleServerObjectListEntry               *next;
  262. };
  263.  
  264. #define WOleDeclareServerObjectClassID()                                \
  265.     public:                                                             \
  266.         static WCLSID _oleClassID;                                      \
  267.         virtual WCLSID OleClassID( void ) { return( _oleClassID ); };
  268.  
  269. #define WOleDefineServerObjectClassID( c, c_id )                        \
  270.     WCLSID c::_oleClassID = c_id;
  271.  
  272. #define WOleDeclareServerObject( c, c_id )                              \
  273.     WOleDeclareServerObjectClassID();                                   \
  274.     protected:                                                          \
  275.         WOleServerObjectListEntry *_serverObjectListEntry;              \
  276.     public:                                                             \
  277.         static WOleServerObject *CreateInstance( WPIUnknown pUnkOuter );
  278.  
  279. #define WOleDefineServerObject( c, c_id, rdb )                          \
  280.     WOleDefineServerObjectClassID( c, c_id );                           \
  281.     static WOleServerObjectRegistryData _WOleSvrRegistryData( c_id, &rdb );\
  282.     static WOleServerObjectListEntry _WOleSvrListEntry( (pfnOleSvrCreateInst)c::CreateInstance, c_id );\
  283.     static WOleServerObject *                                           \
  284.     c::CreateInstance( WPIUnknown pUnkOuter ) {                         \
  285.         c *obj = new c();                                               \
  286.         if( obj ) {                                                     \
  287.             obj->SetUnkOuter( pUnkOuter );                              \
  288.             obj->SetRegistryData( &_WOleSvrRegistryData );              \
  289.         }                                                               \
  290.         return( obj );                                                  \
  291.     }
  292.  
  293. #ifndef _WNO_PRAGMA_PUSH
  294. #pragma enum pop;
  295. #pragma pack(pop);
  296. #endif
  297.  
  298. #endif // _WOLESOBJ_HPP_INCLUDED
  299.  
  300.